//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//                                                                              //
//  Author: meisq                                                               //
//          msq@qq.com                                                          //
//          ALINX(shanghai) Technology Co.,Ltd                                  //
//          heijin                                                              //
//     WEB: http://www.alinx.cn/                                                //
//     BBS: http://www.heijin.org/                                              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
// Copyright (c) 2017,ALINX(shanghai) Technology Co.,Ltd                        //
//                    All rights reserved                                       //
//                                                                              //
// This source file may be used and distributed without restriction provided    //
// that this copyright statement is not removed from the file and that any      //
// derivative work contains the original copyright notice and the associated    //
// disclaimer.                                                                  //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

//===============================================================================
//  Revision History:
//  Date          By                    Revision    Change Description
//--------------------------------------------------------------------------
//  2017/6/19     meisq                 1.0         Original
//  2020/1/28     deepcreatic_XiaoSiyu  2.0         Rewrite
//*******************************************************************************/
module seg_test(
                input      clk,
                input      rst_n,
                output[5:0]seg_sel,
                output[7:0]seg_data
                );

parameter  COUNT_FREQ = 10;
localparam COUNT_RST_NUM = 32'd50_000_000/COUNT_FREQ;

reg[31:0] timer_cnt;
reg en_1hz;                          //1 second , 1 counter enable
always@(posedge clk or negedge rst_n)
begin
    if(rst_n == 1'b0)
    begin
        en_1hz <= 1'b0;
        timer_cnt <= 32'd0;
    end
    else if(timer_cnt >= COUNT_RST_NUM-1)
    begin
        en_1hz <= 1'b1;
        timer_cnt <= 32'd0;
    end
    else
    begin
        en_1hz <= 1'b0;
        timer_cnt <= timer_cnt + 32'd1;
    end
end

genvar i;
wire[3:0] count[5:0];
wire t[5:0];
wire[6:0] seg_data_x[5:0];

count_m10 count10_m0(
    .clk    (clk),
    .rst_n  (rst_n),
    .en     (en_1hz),
    .clr    (1'b0),
    .data   (count[0]),
    .t      (t[0])
 );

generate
    for(i=1; i<6; i=i+1)
    begin: count_m10_loop
        count_m10 count10_mx(
            .clk    (clk),
            .rst_n  (rst_n),
            .en     (t[i-1]),
            .clr    (1'b0),
            .data   (count[i]),
            .t      (t[i])
        );
    end

    for(i=0; i<6; i=i+1)
    begin: seg_decoder_loop
        seg_decoder seg_decoder_mx(
            .bin_data(count[i]),
            .seg_data(seg_data_x[i])
        );
    end

endgenerate

seg_scan seg_scan_m0(
    .clk            (clk),
    .rst_n          (rst_n),
    .seg_sel        (seg_sel),
    .seg_data_out   (seg_data),
    .seg_data_in    ({          //The  decimal point at the highest bit,and low level effecitve
        1'b1, seg_data_x[5],
        1'b1, seg_data_x[4],
        1'b1, seg_data_x[3],
        1'b1, seg_data_x[2],
        1'b0, seg_data_x[1],
        1'b1, seg_data_x[0]
    })
);
endmodule